/**
 * 
 */
package de.nak.roommgmt.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;

import de.nak.roommgmt.model.Lecture;
import de.nak.roommgmt.service.LectureService;

/**
 * Action class for the new lecture functionality.
 * @author Stephan Anft
 */
public class AddLectureAction extends ActionSupport {
	
	/** {@inheritDoc} */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// Get form and service
		LectureForm lectureForm = (LectureForm)form;
		LectureService lectureService = (LectureService)getWebApplicationContext().getBean("lectureService");
		// Get the lecture
		Lecture lecture = lectureForm.getLecture();
		// Create the new lecture
		lectureService.createLecture(lecture.getBegin(), lecture.getEnd(), lectureForm.getCourseId(), lectureForm.getRoomId());
		// Reload the list
		lectureForm.setLectures(lectureService.listLectures());
		return mapping.findForward("success");
	}
}
